Skip to content

Conversation

@pquentin
Copy link
Member

@pquentin pquentin commented Jan 14, 2025

Closes #223

While this does not change any types, it does change the values returned by str(e) and repr(e), so I would like to include this in 9.0 only, without backporting to 8.x.

@pquentin pquentin changed the title Keep last exception cause in errors list Stop hiding cause of last exception Jan 30, 2025
Comment on lines -53 to -55
def __str__(self) -> str:
return str(self.message)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since message is passed in super.__init__(message) and we removed the custom __str__ implementation below, this is already the default implementation.

In Python, __str__ isn't helpful. If you need to know the class name, then __repr__ is required, and our __repr__ implementation contains all information about the current exception, including errors.

>>> e = ValueError("abandon ship!")
>>> str(e)
'abandon ship!'
>>> repr(e)
"ValueError('abandon ship!')"

Comment on lines -70 to -74
def __str__(self) -> str:
if self.errors:
return f"Connection error caused by: {self.errors[0].__class__.__name__}({self.errors[0]})"
return "Connection error"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This __str__ implementation tries to be helpful but hides the current exception to focus on errors, which are past attempts. This comment applies to the other subclasses as well.

Comment on lines +48 to +53
def exception_to_dict(exc: TransportError) -> dict:
return {
"type": exc.__class__.__name__,
"message": exc.message,
"errors": [exception_to_dict(e) for e in exc.errors],
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all the information exposed by __repr__, but in a more structured way which is nicer to test for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

e.errors does not contain the most recent error

1 participant